home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / system-tools-backends-2.0 / scripts / Utils / Report.pm < prev    next >
Encoding:
Perl POD Document  |  2009-04-09  |  11.9 KB  |  291 lines

  1. #!/usr/bin/perl
  2. #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  3.  
  4. # /* Functions for on-the-fly commentary on a tool's work. */
  5. #
  6. # Copyright (C) 2000-2001 Ximian, Inc.
  7. #
  8. # Authors: Hans Petter Jansson <hpj@ximian.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU Library General Public License as published
  12. # by the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. # GNU Library General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Library General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  23.  
  24. # --- Report printing --- #
  25.  
  26. package Utils::Report;
  27.  
  28.  
  29. my $report_threshold = 0;
  30. my $report_table = \%gst_report_message;
  31.  
  32. sub begin
  33. {
  34.   my ($tool) = @_;
  35.   
  36.   &do_report ("begin");
  37.   &enter ();
  38. }
  39.  
  40.  
  41. sub end
  42. {
  43.   &leave ();
  44.   &do_report ("end");
  45. }
  46.  
  47.  
  48. sub set_threshold
  49. {
  50.   $report_threshold = $_[0];
  51. }
  52.  
  53.  
  54. sub enter
  55. {
  56.   # This has been trivialized because it is not working
  57.   # correctly at the moment and is causing some trouble.
  58.   # /* We'll probably replace this with something smarter */
  59.   # (like a detail-level value in the report hash)
  60.   # when the report strings are used at the gui-level again.
  61. #  $gst_report_level ++;
  62.   $gst_report_level = 0;
  63. }
  64.  
  65.  
  66. sub leave
  67. {
  68. #  $gst_report_level --;
  69.   $gst_report_level = 0;
  70. }
  71.  
  72.  
  73. # Escapes a report using the report line format.
  74. sub escape_report
  75. {
  76.   my ($args) = @_;
  77.   my ($arg);
  78.  
  79.   foreach $arg (@$args)
  80.   {
  81.     $arg =~ s/\\/\\\\/g;
  82.     $arg =~ s/::/\\::/g;
  83.   }
  84. }
  85.  
  86.  
  87. $gst_report_level = 0;
  88. $gst_report_started = 0;
  89.  
  90. # Just to trap these errors with the debugger easily.
  91. sub do_report_stderr
  92. {
  93.   my ($major, $key, $res) = @_;
  94.   
  95.   print STDERR "$major::${key}::$res";
  96. }
  97.  
  98. sub do_report
  99. {
  100.   my (@args) = @_;
  101.   my ($key, $major, $minor, $str, $format, $res);
  102.   my $report_message = $report_table;
  103.  
  104.   &escape_report (\@args);
  105.  
  106.   $key = shift @args;
  107.  
  108.   if (! (exists $$report_message{$key}))
  109.   {
  110.       &do_report ("report_minor_unk", $key);
  111.       return;
  112.   }
  113.  
  114.   ($major, $str) = @{$$report_message{$key}};
  115.  
  116.   if (! (exists $gst_report_valid_majors{$major}))
  117.   {
  118.       &do_report ("report_major_unk", $major, join ("::", $key, @args));
  119.       return;
  120.   }
  121.  
  122.   $gst_report_started = 1 if !$gst_report_started && $key eq "begin" && $major eq "sys";
  123.  
  124.   # Verbose (--verbose) output is human-readable only.
  125.   $format = "$str\n";
  126.   $res = sprintf ($format, @args);
  127.  
  128.   if ($Utils::Backend::tool{"do_verbose"} ||
  129.       $major eq "error" ||
  130.       $major eq "debug")
  131.   {
  132.     &do_report_stderr ($major, $key, $res);
  133.   }
  134. }
  135.  
  136. sub add
  137. {
  138.   my $table = shift @_;
  139.  
  140.   if ($table) # Add
  141.   {
  142.     foreach my $key (keys %$table)
  143.     {
  144.       $$report_table{$key} = $$table{$key} unless exists $$report_table{$key};
  145.     }
  146.   }
  147. }
  148.  
  149. # This disables reporting.
  150. &set_threshold (0);
  151.  
  152. %gst_report_valid_majors = (
  153.     "sys"   => 1,
  154.     "error" => 1,
  155.     "warn"  => 1,
  156.     "info"  => 1,
  157.     "debug" => 1
  158.     );
  159.  
  160. %gst_report_message =
  161.     (
  162.      "begin"    => ["sys", "Start of work report."],
  163.      "end"      => ["sys", "End of work report."],
  164.      "compat"   => ["info", "%s."],
  165.  
  166.      "report_major_unk"         => ["error", "Unknown major [%s] in report [%s]."],
  167.      "report_minor_unk"         => ["error", "Unknown minor [%s]."],
  168.  
  169.      "directive_run"            => ["info",  "Running directive [%s] with args [%s]."],
  170.      "directive_unsup"          => ["error", "Directive [%s] not supported."],
  171.      "directive_invalid"        => ["error", "Directive [%s] structure has wrong format."],
  172.      "directive_badargs"        => ["error", "Directive [%s] requires exactly [%s] args in [%s]."],
  173.      "directive_lowargs"        => ["error", "Directive [%s] requires at least [%s] args in [%s]."],
  174.  
  175.      "platform_unsup"           => ["error", "Your platform [%s] is not supported."],
  176.      "platform_undet"           => ["error", "Unable to determine host platform."],
  177.      "platform_success"         => ["sys",   "Configuring for platform [%s] (%s)."],
  178.      "platform_no_table"        => ["error", "No parse/replace table for platform [%s]."],
  179.  
  180.      "xml_unexp_tag"            => ["error", "Unexpected tag [%s]."],
  181.      "xml_unexp_arg"            => ["error", "Unexpected argument [%s] to tag [%s]."],
  182.  
  183.      "file_copy_failed"         => ["debug", "Could not copy file [%s] to [%s]."],
  184.      "file_open_read_failed"    => ["warn",  "Could not open [%s] for reading."],
  185.      "file_open_read_success"   => ["info",  "Reading options from [%s]."],
  186.      "file_open_write_failed"   => ["error", "Failed to write to [%s]."],
  187.      "file_open_write_create"   => ["warn",  "Could not find [%s] for writing. Creating [%s]."],
  188.      "file_open_write_success"  => ["info",  "Writing to [%s]."],
  189.      "file_run_pipe_failed"     => ["warn",  "Failed to pipe command [%s] for reading."],
  190.      "file_run_pipe_success"    => ["info",  "Piping command [%s] for reading."],
  191.      "file_run"                 => ["info",  "Running command [%s]."],
  192.      "file_create_path"         => ["info",  "Directory [%s] created."],
  193.      "file_backup_rotate"       => ["info",  "Backup directory [%s] was rotated."],
  194.      "file_backup_success"      => ["info",  "Saved backup for [%s]."],
  195.      "file_open_filter_failed"  => ["warn",  "No file to patch: [%s]."],
  196.      "file_open_filter_create"  => ["warn",  "Could not find [%s] for patching. Creating [%s]."],
  197.      "file_open_filter_success" => ["info",  "Found [%s]. Patching [%s]."],
  198.      "file_buffer_load"         => ["info",  "Loading file [%s] to buffer."],
  199.      "file_buffer_save"         => ["info",  "Saving buffer to file [%s]."],
  200.      "file_remove"              => ["info",  "Removing file [%s]."],
  201.      "file_locate_tool_success" => ["info",  "Found tool [%s]."],
  202.      "file_locate_tool_failed"  => ["warn",  "Couldn't find tool [%s]."],
  203.      
  204.      "parse_table"              => ["info",  "Parsing option [%s]."],
  205.      "parse_trivial"            => ["info",  "Trivialy passing [%s]."],
  206.      "parse_split"              => ["info",  "Getting option [%s] from [%s]."],
  207.      "parse_split_hash"         => ["info",  "Getting configuration from [%s]."],
  208.      "parse_split_hash_cont"    => ["info",  "Getting configuration from [%s]."],
  209.      "parse_sh"                 => ["info",  "Getting shell option [%s] from [%s]."],
  210.      "parse_kw"                 => ["info",  "Getting keyword [%s] from [%s]."],
  211.      "parse_line_first"         => ["info",  "Getting information from [%s]."],
  212.      "parse_chat"               => ["info",  "Getting chat information from [%s]."],
  213.      "parse_ini"                => ["info",  "Getting option [%s] from [%s], section [%s]."],
  214.      "parse_ifaces_str"         => ["info",  "Getting option [%s] from interface [%s]."],
  215.      "parse_ifaces_kw"          => ["info",  "Getting keyword [%s] from interface [%s]."],
  216.      "parse_ifaces_kw_strange"  => ["warn",  "Keyword for interface [%s] in [%s] had unexpected value."],
  217.  
  218.      "replace_split"            => ["info",  "Replacing key [%s] in [%s]."],
  219.      "replace_sh"               => ["info",  "Replacing shell var [%s] in [%s]."],
  220.      "replace_kw"               => ["info",  "Replacing keyword [%s] in [%s]."],
  221.      "replace_line_first"       => ["info",  "Replacing contents of file [%s]."],
  222.      "replace_chat"             => ["info",  "Replacing values in [%s]."],
  223.      "replace_ini"              => ["info",  "Replacing variable [%s] in section [%s] of [%s]."],
  224.      "replace_del_ini_sect"     => ["info",  "Removing section [%s] from [%s]."],
  225.      "replace_ifaces_str"       => ["info",  "Replacing option [%s] from interface [%s]."],
  226.      "replace_ifaces_kw"        => ["info",  "Replacing keyword [%s] from interface [%s]."],
  227.      
  228.      "service_status_running"   => ["info",  "Service [%s] is running."],
  229.      "service_status_stopped"   => ["info",  "Service [%s] is stopped."],
  230.      "service_sysv_unsupported" => ["info",  "No SystemV support for platform [%s]."],
  231.      "service_sysv_not_found"   => ["warn",  "Could not find SystemV scripts for service [%s]."],
  232.      "service_sysv_no_runlevel" => ["warn",  "Could not find SystemV runlevel [%s] directory [%s]."],
  233.      "service_sysv_remove_link" => ["info",  "Removed SystemV link [%s]."],
  234.      "service_sysv_add_link"    => ["info",  "Created SystemV link [%s]."],
  235.      "service_sysv_op_unk"      => ["error", "Unknown initd operation [%s]."],
  236.      "service_sysv_op_success"  => ["info",  "Service [%s] %s."],
  237.      "service_sysv_op_failed"   => ["warn",  "Service [%s] could not be %s."],
  238.  
  239.      "network_dialing_get"      => ["info",  "Loading ISP configurations."],
  240.      "network_iface_active_get" => ["info",  "Finding active interfaces."],
  241.      "network_iface_is_active"  => ["info",  "Checking if interface [%s] is active."],
  242.      "network_hostname_set"     => ["info",  "Setting hostname to [%s]."],
  243.      "network_dialing_set"      => ["info",  "Saving ISP configurations."],
  244.      "network_remove_pap"       => ["info",  "Removing entry [%s] from [%s]."],
  245.      "network_iface_set"        => ["info",  "Configuring interface [%s]."],
  246.      "network_iface_activate"   => ["info",  "Activating interface [%s]."],
  247.      "network_iface_deactivate" => ["info",  "Deactivating interface [%s]."],
  248.      "network_ifaces_set"       => ["info",  "Setting up interfaces."],
  249.      "network_get_pap_passwd"   => ["info",  "Getting PAP/CHAP password for [%s] from [%s]."],
  250.      "network_get_ppp_option"   => ["info",  "Getting option [%s] from [%s]."],
  251.      "network_set_ppp_option"   => ["info",  "Setting option [%s] in [%s]."],
  252.      "network_set_ppp_connect"  => ["info",  "Setting connect option in [%s]."],
  253.      "network_get_ppp_unsup"    => ["info",  "Getting additional options from [%s]."],
  254.      "network_set_ppp_unsup"    => ["info",  "Setting additional options in [%s]."],
  255.      "network_bootproto_unsup"  => ["warn",  "Boot method [%s] for interface [%s] not supported."],
  256.      "network_get_remote"       => ["info",  "Getting remote address for interface [%s]."],
  257.      "network_set_remote"       => ["info",  "Setting remote address for interface [%s]."],
  258.      "network_ensure_lo"        => ["info",  "Ensuring loopback interface configuration."],
  259.  
  260.      "filesys_mount"            => ["info",  "Mounting [%s] on [%s]."],
  261.      "filesys_mount_failed"     => ["warn",  "Failed to mount [%s] on [%s]."],
  262.      "filesys_unmount"          => ["info",  "Unmounting [%s] from [%s]."],
  263.      "filesys_unmount_failed"   => ["warn",  "Failed to unmount [%s] from [%s]."],
  264.  
  265.      "boot_lilo_failed"         => ["warn",  "Failed to run lilo."],
  266.      "boot_lilo_success"        => ["info",  "Succesfully executed lilo."],
  267.      "boot_conf_read_failed"    => ["error", "Failed to open boot configuration file [%s]."],
  268.      "boot_grub_convert_failed" => ["error", "Conversion of [%s] failed."],
  269.  
  270.      "sfdisk_failed"            => ["error", "Could not run sfdisk."],
  271.  
  272.      "disks_fstab_add"          => ["info",  "Adding [%s] to fstab."],
  273.      "disks_partition_probe"    => ["info",  "Looking for partitions on [%s]."],
  274.      "disks_size_query"         => ["info",  "Querying size of [%s]."],
  275.      "disks_mount"              => ["info",  "Mounting [%s]."],
  276.      "disks_umount"             => ["info",  "Unmounting [%s]."],
  277.      "disks_mount_error"        => ["error", "Could not find mount tools. No mounting done."],
  278.      
  279.      "memory_swap_found"        => ["info",  "Found swap entry [%s]."],
  280.      "memory_swap_probe"        => ["info",  "Looking for swap entries."],
  281.      
  282.      "print_no_printtool"       => ["warn",  "No printtool setup in directory [%s]."],
  283.  
  284.      "time_timezone_scan"       => ["info",  "Scanning timezones."],
  285.      "time_timezone_cmp"        => ["info",  "Scanning timezones: [%s]."],
  286.      "time_timezone_set"        => ["info",  "Setting timezone as [%s]."],
  287.      "time_localtime_set"       => ["info",  "Setting local time as [%s]."]
  288.     );
  289.  
  290. 1;
  291.